/*
 * Copyright (C) 2012 Tomas Shestakov. <http://code.google.com/p/jmmo/>
 */

package jmmo.engine.gameactor

import jmmo.engine.property._

sealed trait ObservableRequest extends Serializable {

  def action: ObservableRequest.Action.Value

  def chain: Seq[Identifier]
}

object ObservableRequest {

  object Action extends Enumeration {
    val
      Get,
      Subscribe,
      GetAndSubscribe,
      Unsubscribe
    = Value
  }

  def unapplySeq(request: ObservableRequest): Option[(ObservableRequest.Action.Value, Seq[Identifier])] =
    if (request eq null) None
    else Some(request.action, request.chain)
}

case class ObservableValueRequest(action: ObservableRequest.Action.Value, chain: Identifier*) extends ObservableRequest

case class ObservableContainerRequest(action: ObservableRequest.Action.Value, chain: Identifier*) extends ObservableRequest

case class FilteredObservableContainerRequest(action: ObservableRequest.Action.Value, eventFilter: ChangeEvent.Filter, obsFilter: Identifiable.Filter, chain: Identifier*) extends ObservableRequest


sealed trait ObservableResponse extends Serializable {

  def chain: Seq[Identifier]

  def value: Any
}

object ObservableResponse {

  def unapplySeq(response: ObservableResponse): Option[(Any, Seq[Identifier])] =
    if (response eq null) None
    else Some(response.value, response.chain)
}

case class ObservableValueResponse[A](value: A, chain: Identifier*) extends ObservableResponse {
  override def toString = "ObservableValueResponse(" + value + (if (chain.nonEmpty) "," else "") + chain.mkString(",") + ")"
}

case class ObservableContainerResponse(value: SilentObservableContainer, chain: Identifier*) extends ObservableResponse {
  override def toString = "ObservableContainerResponse(" + value + (if (chain.nonEmpty) "," else "") + chain.mkString(",") + ")"
}


case class ObservableEvent(source: Identifier, alteration: Alteration, chain: Identifier*) {
  override def toString = "ObservableEvent(" + source + "," + alteration + (if (chain.nonEmpty) "," else "") + chain.mkString(",") + ")"
}